/**
 * @author 
 * @createtime 
 * @class TicketApplyForm
 * @extends Ext.Window
 * @description TicketApply表单
 */
TicketApplyForm=Ext.extend(Ext.Window,{
	//内嵌FormPanel
	formPanel:null,
	//构造函数
	constructor:function(_cfg){
		Ext.applyIf(this,_cfg);
		//必须先初始化组件
		this.initUIComponents();
		TicketApplyForm.superclass.constructor.call(this,{
			id:'TicketApplyFormWin',
			layout:'fit',
			items:this.formPanel,
			modal:true,
			width : 670,
			height : 300,
			maximizable:true,
			title:'票务申请详细信息',
			buttonAlign : 'center',
			buttons:this.buttons
		});
	},//end of the constructor
	//初始化组件
	initUIComponents:function(){
		this.formPanel=new Ext.FormPanel({
				layout : 'form',
				trackResetOnLoad:true,
				bodyStyle: 'padding:10px 10px 10px 10px',
				border:false,
				url : __ctxPath + '/statistics/saveTicketApply.do',
				id : 'TicketApplyForm',
				defaults : {
					anchor : '98%,98%'
				},
				defaultType : 'textfield',
				items : [{
							name : 'ticketApply.id',
							id : 'id',
							xtype:'hidden',
							value : this.id == null ? '' : this.id
						},{
								xtype:'hidden',
								name:'ticketApply.processRunId',
								value:-1
						},{
								xtype: 'container',
								layout:'column',
								defaults:{
									xtype:'label',
									style:{
										margin:'0px 0px 3px 0px'
									}
								},
								items:[
									{
										text:'报告人：',
										columnWidth:0.15
									},
									{
										xtype:'textfield',
										id:'reporter',
										name:'ticketApply.reporter',
										maxLength : 64,
										allowBlank :false,
										columnWidth:0.3,
										value:__currentUser
										
									},
									{
										text:'所属部门：',
										style:'margin-left:10px;',
										columnWidth:0.15
									},
									{
										xtype:'hidden',
										id:'deptId',
										name:'ticketApply.dept.depId',
										value:__currentUserDeptId
									},
									{
										xtype:'textfield',
										id:'deptName',
										value:__currentUserDept,
										maxLength : 64,
										columnWidth:0.4,
										allowBlank :false
									}
								]
							},{
								xtype : 'container',
								layout : 'column',
								defaults:{
									xtype:'label',
									style:{
										margin:'0px 0px 3px 0px'
									}
								},
								items : [ {
											text : '所在公司：',
											columnWidth:0.15
										}, {
											xtype : 'textfield',
											id:'company',
											name:'ticketApply.company',
											allowBlank : false,
											value:__companyName,
	//										readOnly:true,
											columnWidth : 0.85
										}]
						   },{
								xtype: 'container',
								layout:'column',
								defaults:{
									xtype:'label',
									style:{
										margin:'0px 0px 3px 0px'
									}
								},
								items:[
									{
										text:'出行人员：',
										columnWidth:0.15
									},
									{
										xtype:'textfield',
										id:'bookUsers',
										name:'ticketApply.bookUsers',
										maxLength : 64,
										allowBlank :false,
										readOnly:true,
										columnWidth:0.3,
										listeners:{
											'focus' : function() {
														UserSelector.getView(function(n,l,mobile) {
																			Ext.getCmp("bookUsers").setValue(l);
																			Ext.getCmp("bookUserIds").setValue(n);
																			if(l!=''){
																				var userArray = l.split(",");
																				Ext.getCmp("ticketNum").setValue(userArray.length);
																			}else{
																				Ext.getCmp("ticketNum").setValue('');
																			}
																		}, false)
																.show()
													}
										}
									},
									{
										xtype:'hidden',
										id:'bookUserIds',
										name:'ticketApply.bookUserIds'
									},
									{
										text:'需要申请票数：',
										style:'margin-left:10px;',
										columnWidth:0.15
									},
									{
										xtype:'textfield',
										id:'ticketNum',
										name:'ticketApply.ticketNum',
										maxLength : 64,
										columnWidth:0.4,
										readOnly:true,
										allowBlank :false
									}
								]
							},{
								xtype: 'container',
								layout:'column',
								defaults:{
									xtype:'label',
									style:{
										margin:'0px 0px 3px 0px'
									}
								},
								items:[
									{
										text:'出差类型：',
										columnWidth:0.15
									},
									{
										xtype:'combo',
										id:'businessType',
										hiddenName:'ticketApply.businessType',
										mode:'local',
										triggerAction :'all',
										store:['项目','其他'],
										allowBlank :false,
										columnWidth:0.3,
										listeners:{
											select : function(combo,record,index){
												   if(combo.getValue()=='项目'){
												   		Ext.getCmp("projectName").enable();
												   		Ext.getCmp("projectName").allowBlank = false;
												   }else{
												   		Ext.getCmp("projectName").disable();
												   		Ext.getCmp("projectName").allowBlank = true;
												   }
											}
										}
									},
									{
										text:'项目：',
										style:'margin-left:10px;',
										columnWidth:0.15
									},
									{
										xtype:'textfield',
										id:'projectName',
										maxLength : 64,
										columnWidth:0.4,
										readOnly:true,
										disabled:true,
										listeners:{
											focus:function(){
												ProjectNewSelector.getView(function(proId,proName,proNo,contractId,contractNo,contractAmount,proAreaId,proArea){
															Ext.getCmp("projectName").setValue(proName);
															Ext.getCmp("projectId").setValue(proId);
														},true,true).show();
											}
										}
									},
									{
										xtype:'hidden',
										id:'projectId',
										name:'ticketApply.project.id'
									}
								]
							},{
								xtype: 'container',
								layout:'column',
								defaults:{
									xtype:'label',
									style:{
										margin:'0px 0px 3px 0px'
									}
								},
								items:[
									{
										text:'出发地：',
										columnWidth:.15
									},
									{
										xtype:'textfield',
										id:'departure',
										name:'ticketApply.departure',
										maxLength : 64,
										columnWidth:.2
									},
									{
										text:'目的地：',
										style:'margin-left:10px;',
										columnWidth:.1
									},
									{
										xtype:'textfield',
										id:'destination',
										name:'ticketApply.destination',
										maxLength : 64,
										columnWidth:0.2
									},
									{
										text:'票务类型：',
										style:'margin-left:10px;',
										columnWidth:0.15
									},
									{
										xtype:'combo',
										id:'ticketType',
										hiddenName:'ticketApply.ticketType',
										mode:'local',
										triggerAction :'all',
										store:['飞机','火车软卧'],
										allowBlank :false,
										columnWidth:0.2
									}
								]
							},{
								xtype: 'container',
								layout:'column',
								defaults:{
									xtype:'label',
									style:{
										margin:'0px 0px 3px 0px'
									}
								},
								items:[
									{
										text:'出发时间：',
										columnWidth:.15
									},
									{
										xtype:'datetimefield',
										id:'departureTime',
										name:'ticketApply.departureTime',
										emptyText : '---请选择日期---',
	    								format:'Y-m-d H:i',
//	    								minValue:new Date(),
										allowBlank:false,
										maxLength : 64,
										columnWidth:.25
									},
									{
										text:'预订返程票：',
										style:'margin-left:10px;',
										columnWidth:0.15
									},
									{
										xtype:'combo',
										id:'backOrNot',
										hiddenName:'ticketApply.backOrNot',
										mode:'local',
										triggerAction :'all',
										store:['是','否'],
										allowBlank :false,
										columnWidth:0.1,
										listeners:{
											select : function(combo,record,index){
												   if(combo.getValue()=='是'){
												   		Ext.getCmp("backTime").enable();
												   		Ext.getCmp("backTime").allowBlank = false;
												   }else{
												   		Ext.getCmp("backTime").disable();
												   		Ext.getCmp("backTime").allowBlank = true;
												   }
											}
										}
									},
									{
										text:'返程时间：',
										columnWidth:.1
									},
									{
										xtype:'datetimefield',
										id:'backTime',
										name:'ticketApply.backTime',
	    								format:'Y-m-d H:i',
										disabled:true,
//										minValue:new Date(),
										columnWidth:0.25
									}
								]
							},{
								xtype : 'container',
								layout : 'column',
								defaults:{
									xtype:'label',
									style:{
										margin:'0px 0px 3px 0px'
									}
								},
								items : [ {
											text : '申请原因：',
											columnWidth:0.15
										}, {
											xtype : 'textarea',
											id:'applyReason',
											name:'ticketApply.applyReason',
											allowBlank : false,
	//										readOnly:true,
											columnWidth : 0.85
										}]
						   }
							]
			});
		//加载表单对应的数据	
		if (this.id != null && this.id != 'undefined') {
			this.formPanel.getForm().load({
				deferredRender : false,
				url : __ctxPath + '/statistics/getTicketApply.do?id='+ this.id,
				waitMsg : '正在载入数据...',
				success : function(form, action) {
					 var res = Ext.util.JSON.decode(action.response.responseText).data;
					 if(res.businessType=='项目'){
					 	Ext.getCmp("projectName").enable();
						Ext.getCmp("projectName").allowBlank = false;
					 }else{
					 	Ext.getCmp("projectName").disable();
						Ext.getCmp("projectName").allowBlank = true;
					 }
					 if(res.backOrNot=='是'){
					 	Ext.getCmp("backTime").enable();
						Ext.getCmp("backTime").allowBlank = false;
					 }else{
					 	Ext.getCmp("backTime").disable();
						Ext.getCmp("backTime").allowBlank = true;
					 }
					 if(res.project!=null){
					 	Ext.getCmp("projectId").setValue(res.project.id);
						Ext.getCmp("projectId").originalValue = res.project.id;
						Ext.getCmp("projectName").setValue(res.project.proName);
						Ext.getCmp("projectName").originalValue = res.project.proName;
					 }
					 if(res.dept!=null){
						Ext.getCmp("deptId").setValue(res.dept.depId);
						Ext.getCmp("deptId").originalValue = res.dept.depId;
						Ext.getCmp("deptName").setValue(res.dept.depName);
						Ext.getCmp("deptName").originalValue = res.dept.depName;
					}
				},
				failure : function(form, action) {
				}
			});
		}
		//初始化功能按钮
		this.buttons=[{
				text : '保存',
				iconCls : 'btn-save',
//				hidden:true,
				handler :this.save.createCallback(this.formPanel,this)
			}, {
				text : '重置',
				iconCls : 'btn-reset',
//				hidden:true,
				handler :this.reset.createCallback(this.formPanel)
			},{
				text : '关闭',
				iconCls : 'btn-cancel',
				handler : this.cancel.createCallback(this)
			}];
	},//end of the initcomponents
	
	/**
	 * 重置
	 * @param {} formPanel
	 */
	reset:function(formPanel){
		formPanel.getForm().reset();
	},
	/**
	 * 取消
	 * @param {} window
	 */
	cancel:function(window){
		window.close();
	},
	/**
	 * 保存记录
	 */
	save:function(formPanel,window){
		if (formPanel.getForm().isValid()) {
			formPanel.getForm().submit({
				method : 'POST',
				waitMsg : '正在提交数据...',
				success : function(fp, action) {
					Ext.ux.Toast.msg('操作信息', '成功保存信息！');
					var gridPanel=Ext.getCmp('TicketApplyGrid');
					if(gridPanel!=null){
						gridPanel.getStore().reload();
					}
					window.close();
				},
				failure : function(fp, action) {
					Ext.MessageBox.show({
								title : '操作信息',
								msg : '信息保存出错，请联系管理员！',
								buttons : Ext.MessageBox.OK,
								icon : Ext.MessageBox.ERROR
							});
					window.close();
				}
			});
		}
	}//end of save
	
});